
let app = getApp();
var applet_park_api_url = app.globalData.applet_park_api_url;
const {
  requestDataparams
} = require('../../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    carNumber:[],
    openId:'',
    token:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var that = this;
     var openId = wx.getStorageSync('OPENID');
     var token = wx.getStorageSync('TOKEN');
     that.setData({
      openId:openId,
      token:token
     })
     
  },
  inputeidt(e){
      
      var that = this;
      var carNumber = that.data.carNumber;
      var id = e.currentTarget.dataset.id;
      var value = e.detail.value;
      carNumber = carNumber + value
      that.setData({
         carNumber:carNumber
      })
      
         
  },
  submitAddCar(){
     var that =this;
      requestDataparams('/api/parkInfo/addLicensePlate',{ openId:that.data.openId,licPlateNum: that.data.carNumber,type:1 }, 'POST','json').then(response=>{
                 
                  if(response.data.code == 0){
                    wx.showToast({
                      title: '添加成功',
                      icon:'none'
                    })
                    var pages = getCurrentPages();
                    var prevPage = pages[pages.length - 2]; //上一个页面
                    prevPage.initPage();
                    wx.navigateBack({
                      delta: 1
                    })
                  }else{
                    wx.showToast({
                      title: '失败',
                      icon:'none'
                    })
                  }
          })
  },
  judgeFocus: function () {
    var arr = this.data.boxcodearr;
    var num = arr.length;
    if(num == 0) num = 1;
    this.setData({
      focusnum : num
    })
  },
  goNextInput(el){
    var txts = document.querySelectorAll(el);
    for(var i = 0; i<txts.length;i++){
      var t = txts[i];
      t.index = i;
      t.setAttribute("readonly", true);
      t.onkeyup=function(){
          this.value=this.value.replace(/^(.).*$/,'$1');
          var next = this.index + 1;
          if(next > txts.length - 1) return;
          txts[next].removeAttribute("readonly");
          if (this.value) {
              txts[next].focus();
          }

      }
    }
    txts[0].removeAttribute("readonly");
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})